<?php
include dirname(dirname(dirname(__FILE__))).'/include/db_connect.php';

function getExcellentWorkerId() {
	$conn = get_db_conn();
	$sql = 'select id from excellent_worker limit 0,1;';
	$result = mysql_query($sql,$conn) or die("db error");
	if(mysql_num_rows($result)==0) {
		$sql = 'insert into excellent_worker(update_time) values("'.date('Y-m-d h:i:s').'");';
		mysql_query($sql,$conn) or die("db error");
		$sql = 'select id from excellent_worker limit 0,1;';
		$result = mysql_query($sql,$conn) or die("db error");
	}
	$row = mysql_fetch_array($result);
	return $row['id'];
}

function updateExcellentWorker($worker1_id,$worker2_id,$author_id) {
	$conn = get_db_conn();
	$sql = 'update excellent_worker set worker1_id = '.$worker1_id.' , worker2_id = '
			.$worker2_id.' , author_id = '.$author_id.' , update_time = "'
			.date('Y-m-d h:i:s').'" where id = '.getExcellentWorkerId().' ;';
	mysql_query($sql,$conn) or die("db error");
	return true;
}

function getExcellentWorker() {
	$conn = get_db_conn();
	$sql = 'select worker1_id,worker2_id from excellent_worker where id = '.getExcellentWorkerId().';';
	$result = mysql_query($sql,$conn) or die("db error");
	$row = mysql_fetch_array($result);
	return $row;
}

function getExcellentWorkerUpdateTime() {
	$conn = get_db_conn();
	$sql = 'select update_time from excellent_worker where id = '.getExcellentWorkerId().';';
	$result = mysql_query($sql,$conn) or die("db error");
	$row = mysql_fetch_array($result);
	return $row['update_time'];
}

function getExcellentWorkerUpdateAuthorId() {
	$conn = get_db_conn();
	$sql = 'select author_id from excellent_worker where id = '.getExcellentWorkerId().';';
	$result = mysql_query($sql,$conn) or die("db error");
	$row = mysql_fetch_array($result);
	return $row['author_id'];
}